home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / umich / falcon / programm.ing / nt_dsp1.lzh / NT_DSP1.MSA / SORT / SORT1.ASM next >
Assembly Source File  |  1989-01-24  |  1KB  |  48 lines

  1. ;
  2. ; This program originally available on the Motorola DSP bulletin board.
  3. ; It is provided under a DISCLAIMER OF WARRANTY available from
  4. ; Motorola DSP Operation, 6501 Wm. Cannon Drive W., Austin, Tx., 78735.
  5. ; Last Update 11 Sep 87   Version 1.0
  6. ;
  7. ; Sorting by Straight Selection
  8. ;
  9. sort1   macro   ARRAY,N_ITEMS   
  10. sort1   ident   1,1
  11.  
  12. ; reference: Niklaus Writh, "Algorithms + Data Structures = Programs", 
  13. ;            Prentice-Hall, 1976, Program 2.3, page 64
  14. ;
  15. ; ARRAY = location of an array of numbers in X memory space, 
  16. ;         first item is located at ARRAY.
  17. ; N_ITEMS = number of items in the array
  18. ;
  19. ; register usage:
  20. ;       r0=(j)          r1=(k)          r2=(i)
  21. ;       r4=j'           n1=-2 offset
  22. ;       a=x             b       
  23. ;       y0              
  24. ;       uses 4 words of stack
  25. ;       assumes m0..m2 = $ffff
  26. ;
  27.         move            #N_ITEMS,r4        
  28.         move            #ARRAY,r2
  29.         move            #-2,n1  
  30.  
  31.         do      #N_ITEMS-1,_loop2
  32.         lua     (r2)+,r0
  33.         move    x:(r2),a        y:(r4)-,b
  34.         move    x:(r0)+,b 
  35.         move    r0,r1
  36.  
  37.         do      r4,_loop1
  38.         cmp     b,a     x:(r0)+,b       b,y0
  39.         tge     y0,a    r0,r1
  40. _loop1
  41.         move    x:(r2),y0
  42.         move    a,x:(r2)+
  43.         move    y0,x:(r1+n1)
  44. _loop2
  45.         endm
  46.  
  47.